package org.darcy.framework.blog.tag;

import java.util.Map;

import org.darcy.framework.blog.business.enums.ArticleStatusEnum;
import org.darcy.model.BizArticleModel;
import org.darcy.service.BizArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 文章相关的自定义标签
 *
 */
@Component
public class ArticleTags extends BaseTag {

	@Autowired
	private BizArticleService articleService;

	public ArticleTags() {
		super(ArticleTags.class.getName());
	}

	public Object recentArticles(Map params) {
		int pageSize = this.getPageSize(params);
		return articleService.listRecent(pageSize);
	}

	public Object recommendedList(Map params) {
		int pageSize = this.getPageSize(params);
		return articleService.listRecommended(pageSize);
	}

	public Object randomList(Map params) {
		int pageSize = this.getPageSize(params);
		return articleService.listRandom(pageSize);
	}

	public Object hotList(Map params) {
		int pageSize = this.getPageSize(params);
		return articleService.listHotArticle(pageSize);
	}

	public Object typeList(Map params) {
		int pageSize = this.getPageSize(params);
		long typeId = -1;
		String typeStr = getParam(params, "typeId");
		if (!StringUtils.isEmpty(typeStr)) {
			typeId = Long.parseLong(typeStr);
		}
		// 按文章分类查询
		BizArticleModel vo = new BizArticleModel();
		vo.setTypeId(typeId);
		// 已发布状态
		vo.setStatus(ArticleStatusEnum.PUBLISHED.getCode());
		vo.setPageSize(pageSize);
		IPage<BizArticleModel> pageInfo = articleService.query(vo);
		return pageInfo.getRecords();
	}
}
